//
//  FSMeetingOpinionController.m
//  Trade
//


//已收文件的填写意见环节



#import "FSMeetingOpinionController.h"
#import "FSInputOpinionView.h"
#import "FSInputRootView.h"

@interface FSMeetingOpinionController ()

//人员详情
@property (weak, nonatomic) IBOutlet FSInputRootView *inputRootView;


@property (weak, nonatomic) IBOutlet UITextView *textView;


- (IBAction)addAction:(id)sender;

@end

@implementation FSMeetingOpinionController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setRightItem];
}

-(void)setRightItem{
    
    UIBarButtonItem * rightItem = [[UIBarButtonItem alloc] initWithTitle:@"提交" style:UIBarButtonItemStylePlain target:self action:@selector(submitAction)];
    
    self.navigationItem.rightBarButtonItem = rightItem;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row == 0) {
        return 84;
    }else if (indexPath.row == 1) {
        return [self.inputRootView inputRootViewHeight];
    }else if (indexPath.row == 2){
        return 135;
    }
    return 44;
}

//增加按钮
- (IBAction)addAction:(id)sender {
    
    [self.inputRootView addInputOpinionView];
    [self.tableView reloadData];
//    [self.tableView layoutIfNeeded];
    
} 

-(void)submitAction{
    [self.view endEditing:YES];
    
    NSArray * inputInfoArray = [self.inputRootView getInfo];
    NSMutableDictionary * dict = [NSMutableDictionary dictionary];
    [dict setObject:inputInfoArray forKey:@"info"];
    if (self.textView.text.length !=0) {
        [dict setObject:self.textView.text forKey:@"reason"];
    }else{
        [dict setObject:@"" forKey:@"reason"];
    }
    
    NSData * data  = [NSJSONSerialization dataWithJSONObject:dict options:0 error:NULL];
    NSString * infoString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
    
    NSString * userId = [[NSUserDefaults standardUserDefaults]objectForKey:@"userId"];
    NSArray * array =@[@{@"userId":userId},@{@"unid":self.identifier},@{@"formxml":infoString}];
    [HttpTools requestWithURL:KexchexchangeURL arrays:array method:KSetSubmitMeeting success:^(id JSON) {
        [self.view.window makeToast:@"提交意见成功"];
        [self.navigationController popViewControllerAnimated:YES];
    } failure:^(NSError *error) {
        [self.view.window makeToast:@"提交意见失败"];
    }];
    
}


@end

















